package www.yingdi365.com.viewholder;

import android.support.annotation.LayoutRes;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;

import java.util.Collections;
import java.util.List;

import www.yingdi365.com.R;
import www.yingdi365.com.constant.Constant;
import www.yingdi365.com.model.AppMicrofacies;

/**
 * Created by Administrator on 2017/3/28 0028.
 */
public class WeiXiangBenViewHolder extends BaseViewHolder<AppMicrofacies> {

    private final ImageView imageBig;
    private final TextView textName;
    private final TextView textDes;

    public WeiXiangBenViewHolder(ViewGroup parent, @LayoutRes int res) {
        super(parent, res);
        imageBig = $(R.id.imageBig);
        textName = $(R.id.textName);
        textDes = $(R.id.textDes);
    }

    @Override
    public void setData(AppMicrofacies data) {
        super.setData(data);
        List<AppMicrofacies.PictureListBean> pictureList = data.getPictureList();
        for (int i = 0; i < pictureList.size(); i++) {
            float kuanGaoBi = (float) pictureList.get(i).getHeight() / (float) pictureList.get(i).getWidth();
            pictureList.get(i).setKuanGaoBi(kuanGaoBi);
        }
        Collections.sort(data.getPictureList());
        if (pictureList.size() == 0) {
            Glide.with(getContext())
                    .load(R.mipmap.album)
                    .placeholder(R.mipmap.album)
                    .into(imageBig);
        } else {
            Glide.with(getContext())
                    .load(pictureList.get(0).getUrl()+ Constant.TuPianYaSuo)
                    .placeholder(R.mipmap.album)
                    .into(imageBig);
        }
        textName.setText(data.getName());
        textDes.setText(data.getDescribe());
    }
}
